/**
 * long description for the file
 *
 * @summary short description for the file
 * @author wu[308822989@qq.com]
 *
 * Created at     : 2019-06-12 23:08:28 
 * Last modified  : 2019-06-18 16:22:01
 */

var express = require('express');
var router = express.Router();

const { Yiyunpay } = require('../utils/yiyunpay.js');
const YiyunpayClass = new Yiyunpay();

/* GET home page. */
router.get('/', async function (req, res, next) {
    let typeItems = await YiyunpayClass.typeItems();
    let qcodeItems = await YiyunpayClass.qcodeItems();
    res.render('index', { title: 'index', typeItems, qcodeItems });
});

router.get('/select', async function (req, res, next) {
    let typeItems = await YiyunpayClass.typeItems();
    let qcodeItems = await YiyunpayClass.qcodeItems();
    res.json({ typeItems, qcodeItems });
});

/**
 * 
 */
router.post('/orderadd', async function (req, res, next) {
    //  
    let order_code = +new Date() + '';
    let order_qq = '308822989';
    let order_uid = '123456';
    let { qcode_id, type_id } = req.body;
    let setOrder = await YiyunpayClass.orderAdd({ order_code, order_qq, qcode_id, type_id, order_uid });
    res.json(setOrder);
});

/**
 * 
 */
router.get('/orderinfo', async function (req, res, next) {
    let { order_id } = req.query;
    let getOrderInfo = await YiyunpayClass.orderInfo(order_id);
    res.json(getOrderInfo);
});

router.get('/orderback', function (req, res, next) {
    res.render('index', { title: 'Express' });
});

module.exports = router;
